cmake_minimum_required(VERSION 3.5)

set(${PROJECT_NAME} GPU-perf-cuda)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")

set(EXAMPLES
    maxsp-compute
    maxdp-compute
    maxint-compute
    maxhalf-compute
    bs-download-speed
    bs-readback-speed
    gmem-read-bw
    fft-test
    gemm-test
)

foreach(EXAMPLE ${EXAMPLES})
  file(GLOB SOURCE ${EXAMPLE}/*.cu)
  set(EXAMPLE_SRC ${EXAMPLE_SRC} ${SOURCE})
endforeach(EXAMPLE)

if( "$ENV{GPU_PLATFORM}" STREQUAL "MTGPU" )
    if( "$ENV{GPU_ARCH}" STREQUAL "" )
        set(_ARCH_ "10")
    else()
        set(_ARCH_ "$ENV{GPU_ARCH}")
    endif()
    set(MUSA_MCC_FLAGS --offload-arch=mp_${_ARCH_} -mllvm -mtgpu-prera-internal-opt-method=bypass_dst)
    musa_add_executable(${PROJECT_NAME} main.cpp  ${EXAMPLE_SRC})
else()
    if( "$ENV{GPU_ARCH}" STREQUAL "" )
        set(_ARCH_ "53")
    else()
        set(_ARCH_ "$ENV{GPU_ARCH}")
    endif()
    set(CUDA_NVCC_FLAGS -arch=sm_${_ARCH_})
    cuda_add_executable(${PROJECT_NAME} main.cpp  ${EXAMPLE_SRC})
endif()

target_link_libraries(${PROJECT_NAME}
    ${MATH_LIBRARIES}
    common
    cuda-framwork
    dl pthread)

include_directories(${CMAKE_SOURCE_DIR}/includes)
